package service.wechatlab.impl;

import java.io.File;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.hibernate.jpa.criteria.expression.function.CurrentTimeFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.wechatlab.DataSetDao;
import pojo.weichatlab.WechatLabel;
import service.wechatlab.DataSetService;
@Service
public class DataSetServiceImpl implements DataSetService {
	@Autowired
	DataSetDao dad;

	@Override
	public boolean modLabel(int k, File f){
		BigDecimal lasttime = new BigDecimal("1494495333948");
		System.out.println(System.currentTimeMillis());
		if(!dad.createTampTable() || !dad.addWechatLabel(k))
			return false;
		List<WechatLabel> wl = dad.selectWechatLabel();
		try(FileWriter fw = new FileWriter(f)){
			for(WechatLabel l:wl){
					fw.write("$"+l.getClasses()+"\t");
					fw.write(l.getWechatid() + "\t");
					fw.write(l.getUrl()+"\t");
					fw.write(l.getTitle()+"\t");
					fw.write(l.getName()+"\t");
					fw.write(l.getAccount()+"\t");
					fw.write(l.getBrief()+"\t");
					fw.write(l.getContent()+"\t");
					fw.write(l.getDate()+"");
					fw.write("\r\n");
			}
			return true;
		}catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
